package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

public class CorrodeSkill extends BaseSkill {

    public CorrodeSkill(int level) {
        super(level);
    }

    public CorrodeSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public CorrodeSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return "腐蚀技能，每次攻击对盔甲额外造成（技能等级*2）伤害。";
    }

    public SkillRarity getSkillRarity() {
        return SkillRarity.Rare;
    }

    @Override
    public boolean onAttack(MobEntity attacker, LivingEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if (target.getEquippedStack(EquipmentSlot.HEAD) != null) {
            int Headdamage = target.getEquippedStack(EquipmentSlot.HEAD).getDamage();
            target.getEquippedStack(EquipmentSlot.HEAD).damage(Headdamage + getSkillLevel() * 2, target, p -> p.sendEquipmentBreakStatus(EquipmentSlot.HEAD));
        }
        if (target.getEquippedStack(EquipmentSlot.CHEST) != null) {
            int CHESTdamage = target.getEquippedStack(EquipmentSlot.CHEST).getDamage();
            target.getEquippedStack(EquipmentSlot.CHEST).damage(CHESTdamage + getSkillLevel() * 2, target, p -> p.sendEquipmentBreakStatus(EquipmentSlot.CHEST));
        }
        if (target.getEquippedStack(EquipmentSlot.LEGS) != null) {
            int LEGSdamage = target.getEquippedStack(EquipmentSlot.LEGS).getDamage();
            target.getEquippedStack(EquipmentSlot.LEGS).damage(LEGSdamage + getSkillLevel() * 2, target, p -> p.sendEquipmentBreakStatus(EquipmentSlot.LEGS));
        }
        if (target.getEquippedStack(EquipmentSlot.FEET) != null) {
            int FEETdamage = target.getEquippedStack(EquipmentSlot.FEET).getDamage();
            target.getEquippedStack(EquipmentSlot.FEET).damage(FEETdamage + getSkillLevel() * 2, target, p -> p.sendEquipmentBreakStatus(EquipmentSlot.FEET));
        }
        return true;
    }
}
